﻿using System;
namespace Kis.Xroad.Eu {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="Menetlus", Namespace="http://kis.x-road.eu/", Target=typeof(Menetlus))]
    public class MenetlusSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected Menetlus clazz;
        
        public MenetlusSerializer(Menetlus clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXmlAttributes(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXmlAttributes(Writer);
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("Osaline");
            if (clazz.Osaline!=null) {
                global::Xtee.Core.SerializationMetadata metaOsaline = this.GetMetaData(clazz.Osaline);
                if (ShouldWriteTypeAttribute(typeof(global::Kis.Xroad.Eu.Osaline), clazz.Osaline.GetType())) {
                    Writer.WriteTypeAttribute(metaOsaline.TypeQualifiedName.Namespace, metaOsaline.TypeQualifiedName.Name);
                }
                var osalineSerializer = metaOsaline.NewSerializer(clazz.Osaline);
                osalineSerializer.WriteXmlAttributes(Writer);
                osalineSerializer.WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Osaline");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXmlAttributes(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXmlAttributes(Reader);
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="Osaline") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Menetlus>Osaline");
                }
                global::Xtee.Core.SerializationMetadata metaOsaline = this.GetMetaData<global::Kis.Xroad.Eu.Osaline>(Reader, "Osaline", "http://kis.x-road.eu/");
                clazz.Osaline = metaOsaline.NewEntity<global::Kis.Xroad.Eu.Osaline>();
                if ((Reader.IsEmptyElement == false)) {
                    var osalineSerializer = metaOsaline.NewSerializer(clazz.Osaline);
                    osalineSerializer.ReadXmlAttributes(Reader);
                    Reader.ReadStartElement("Osaline");
                    osalineSerializer.ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>Menetlus>Osaline", Reader.LocalName);
            }
        }
    }
}
